﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BooksManagermentSystem
{
    public partial class DeleteAdmin_form : Form
    {
        public DeleteAdmin_form()
        {
            InitializeComponent();
        }
        private void DeleteAdmin_form_Load(object sender, EventArgs e)
        {
            fuck();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string account = comboBox1.Text;
            DialogResult rt = MessageBox.Show($"确认删除管理员【{account}】吗？", "提示", MessageBoxButtons.YesNo);
            if (rt == DialogResult.Yes)
            {
                string sql = $"delete from AdminInfo where account = '{account}'";
                if(DBhelper.NonQuery(sql))
                {
                    MessageBox.Show("删除成功！");
                    fuck();
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }

        private void fuck()
        {
            DataTable dt = DBhelper.GetDataTable("select * from AdminInfo");
            comboBox1.DataSource = dt;
            comboBox1.DisplayMember = "account";
        }
    }
}
